package com.hmall.common.config;

import com.hmall.common.interceptor.UserInfoInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
//因为网关不是后端的技术,没有web依赖,没有WebMvcConfigurer类,无法使用这个拦截器,也不需要使用这个拦截器,
// 所以把他排除
@ConditionalOnClass(WebMvcConfigurer.class)
public class MvcConfig implements WebMvcConfigurer {
//    @Autowired
//    private UserInfoInterceptor userInfoInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册拦截器拦截所有
//        registry.addInterceptor(userInfoInterceptor).addPathPatterns("/**");
        registry.addInterceptor(new UserInfoInterceptor()).addPathPatterns("/**");
    }
}
